<?xml version="1.0" encoding="UTF-8"?>

<confluence-configuration>

  <setupStep>{{ atl_setup_step | default('setupstart') }}</setupStep>
  <setupType>{{ atl_setup_type | default('custom') }}</setupType>
  <buildNumber>{{ atl_build_number | default('0') }}</buildNumber>

  <properties>
    <property name="confluence.database.connection.type">database-type-standard</property>
    <property name="struts.multipart.saveDir">${localHome}/temp</property>
    <property name="webwork.multipart.saveDir">${localHome}/temp</property>
    <property name="attachments.dir">${confluenceHome}/attachments</property>
    <property name="lucene.index.dir">{{ atl_lucene_index_dir | default('${confluenceHome}/index') }}</property>

    {# We need mappings for "oracle12c" and "oracle" to remain backwards compatible with Confluence 7.3.0 and earlier. Oracle 19c support was added in Confluence 7.3.1 and changed the database type name for oracle databases from "oracle12c" to "oracle" #}
    {% if atl_jdbc_url is defined %}
      {% set databases =  {
           "mysql": ["com.mysql.jdbc.Driver", "MySQLDialect"],
           "postgresql": ["org.postgresql.Driver", "PostgreSQLDialect"],
           "mssql": ["com.microsoft.sqlserver.jdbc.SQLServerDriver", "SQLServerDialect"],
           "oracle12c": ["oracle.jdbc.driver.OracleDriver", "OracleDialect"],
           "oracle": ["oracle.jdbc.driver.OracleDriver", "OracleDialect"]
          } %}
      <property name="confluence.database.choice">{{ atl_db_type }}</property>

      <property name="hibernate.connection.url">{{ atl_jdbc_url }}</property>
      <property name="hibernate.connection.username">{{ atl_jdbc_user }}</property>
      <property name="hibernate.connection.password">{{ atl_jdbc_password }}</property>
      <property name="hibernate.connection.driver_class">{{ databases[atl_db_type][0] }}</property>
      <property name="hibernate.dialect">com.atlassian.confluence.impl.hibernate.dialect.{{ databases[atl_db_type][1] }}</property>

      {# Confluence versions 7.13 and newer #}
      {% if (confluence_version.split(".")[0] | int() == 7 and confluence_version.split(".")[1] | int() <= 13) or confluence_version.split(".")[0] | int() < 7 %}
      <property name="hibernate.c3p0.min_size">{{ atl_db_poolminsize | default('20') }}</property>
      <property name="hibernate.c3p0.max_size">{{ atl_db_poolmaxsize | default('100') }}</property>
      <property name="hibernate.c3p0.timeout">{{ atl_db_timeout | default('30') }}</property>
      <property name="hibernate.c3p0.idle_test_period">{{ atl_db_idletestperiod | default('100') }}</property>
      <property name="hibernate.c3p0.max_statements">{{ atl_db_maxstatements | default('0') }}</property>
      <property name="hibernate.c3p0.validate">{{ atl_db_validate | default('true') }}</property>
      <property name="hibernate.c3p0.acquire_increment">{{ atl_db_acquireincrement | default('1') }}</property>
      <property name="hibernate.c3p0.preferredTestQuery">{{ atl_db_validationquery | default('select 1') }}</property>
      {% else %}
      <property name="hibernate.hikari.idleTimeout">{{ (atl_db_timeout | default(30) | int) * 1000 }}</property>
      <property name="hibernate.hikari.maximumPoolSize">{{ atl_db_poolmaxsize | default('100') }}</property>
      <property name="hibernate.hikari.minimumIdle">{{ atl_db_poolminsize | default('20') }}</property>
      <property name="hibernate.hikari.registerMbeans">true</property>
      {% endif %}

    {% endif %}

    {% if atl_cluster_type is defined %}
      <property name="confluence.cluster">true</property>
      <property name="confluence.cluster.name">{{ atl_cluster_name }}</property>
      <property name="confluence.cluster.node.name">{{ atl_cluster_node_name }}</property>
      <property name="confluence.cluster.home">{{ atl_product_home_shared | default(confluence_shared_home) | default('') }}</property>
      <property name="shared-home">{{ atl_product_home_shared | default(confluence_shared_home) | default('') }}</property>

      <property name="confluence.cluster.join.type">{{ atl_cluster_type }}</property>
      {% if atl_cluster_type == 'aws' %}
        <property name="confluence.cluster.aws.iam.role">{{ atl_hazelcast_network_aws_iam_role }}</property>
        <property name="confluence.cluster.aws.region">{{ atl_hazelcast_network_aws_iam_region }}</property>
        <property name="confluence.cluster.aws.host.header">{{ atl_hazelcast_network_aws_host_header }}</property>
        <property name="confluence.cluster.aws.security.group.name">{{ atl_hazelcast_network_aws_security_group }}</property>
        <property name="confluence.cluster.aws.tag.key">{{ atl_hazelcast_network_aws_tag_key }}</property>
        <property name="confluence.cluster.aws.tag.value">{{ atl_hazelcast_network_aws_tag_value }}</property>
        <property name="confluence.cluster.ttl">{{ atl_cluster_ttl }}</property>

      {% elif atl_cluster_type == 'tcp_ip' %}
        <property name="confluence.cluster.peers">{{ atl_cluster_peers }}</property>

      {% elif atl_cluster_type == 'multicast' %}
        <property name="confluence.cluster.address">{{ atl_cluster_address }}</property>
        <property name="confluence.cluster.ttl">{{ atl_cluster_ttl }}</property>

      {% endif %}

    {% endif %}

    {% if atl_license_key is defined %}
      <property name="atlassian.license.message">{{ atl_license_key }}</property>
    {% endif %}

    {% if atl_tomcat_contextpath is defined and atl_tomcat_contextpath != '' %}
      <property name="confluence.webapp.context.path">/{{ atl_tomcat_contextpath }}</property>
    {% endif %}

    {% if atl_snapshot_used is defined %}
      <property name="hibernate.setup">true</property>
    {% endif %}

  </properties>
</confluence-configuration>
